package com.neusoft.service.impl;

import java.math.BigDecimal;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neusoft.mapper.CommentMapper;
import com.neusoft.mapper.OrdersMapper;
import com.neusoft.po.Comment;
import com.neusoft.service.CommentService;
import com.neusoft.util.CommonUtil;

@Service
public class CommentServiceImpl implements CommentService {

	@Autowired
	private CommentMapper commentMapper;
	
	@Autowired
	private OrdersMapper ordersMapper;

	@Override
	public List<Comment> listCommentByBusinessId(Integer businessId) {
		return commentMapper.listCommentByBusinessId(businessId);
	}

	@Override
	public List<Comment> listCommentByUserId(String userId) {
		return commentMapper.listCommentByUserId(userId);
	}

	@Override
	public Comment getCommentByOrderId(Integer orderId) {
		return commentMapper.getCommentByOrderId(orderId);
	}

	@Override
	public Double getAverageRatingByBusinessId(Integer businessId) {
		return commentMapper.getAverageRatingByBusinessId(businessId);
	}

	@Override
	public int saveComment(String userId, Integer businessId, Integer orderId, String commentContent, Integer rating,
			Boolean isAnonymous) {
		Comment comment = new Comment();
		comment.setUserId(userId);
		comment.setBusinessId(businessId);
		comment.setOrderId(orderId);
		comment.setCommentContent(commentContent);
		comment.setRating(rating);
		comment.setIsAnonymous(isAnonymous);
		comment.setCreateTime(CommonUtil.getCurrentDate1());
		comment.setUpdateTime(CommonUtil.getCurrentDate1());
		commentMapper.saveComment(comment);
		return ordersMapper.updateOrderComment(orderId);
	}

	@Override
	public int updateComment(Integer commentId, String commentContent, Integer rating, Boolean isAnonymous) {
		String updateTime = CommonUtil.getCurrentDate();
		return commentMapper.updateComment(commentId, commentContent, rating, isAnonymous, updateTime);
	}

	@Override
	public int deleteComment(Integer commentId) {
		return commentMapper.deleteComment(commentId);
	}
}